<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {
		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center', rowspan:2},				
				{ field : 'no_surat', title : 'No Surat', width:150, sortable:true, rowspan:2},
				{ field : 'nama_penyelenggara', title : 'Nama Penyelenggara', width:200, sortable:true, rowspan:2},
				{ field : 'alamat', title : 'Alamat', width:150, sortable:true, rowspan:2},
				{ field : 'diwakili_oleh', title : 'Diwakali Oleh', width:120, sortable:true, rowspan:2},
				{ field : 'no_telp', title : 'No Telp', width:120, sortable:true, rowspan:2},
				{ field : 'nama_kegiatan', title : 'Nama Kegiatan', width:170, sortable:true, rowspan:2},
				{ field : 'tanggal_mulai_kegiatan', title : 'Tanggal Mulai Kegiatan', width:150, sortable:true, rowspan:2},
				{ field : 'tanggal_selesai_kegiatan', title : 'Tanggal Selesai Kegiatan', width:150, sortable:true, rowspan:2},
				{ field : 'pukul', title : 'Pukul', width:100, sortable:true, rowspan:2},
				{ field : 'tempat_kegiatan', title : 'Tempat Kegiatan', width:170, sortable:true, rowspan:2},
				{ field : 'catatan_kegiatan', title : 'Catatan Kegiatan', width:170, sortable:true, rowspan:2},
				]
			]
		});
		 
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'no_surat', type: 'text', size: 'medium', maxlength: 60, noempty:true },
			{ name: 'nama_penyelenggara', type: 'text', size: 'long', maxlength: 200, noempty:true },
			{ name: 'alamat', type: 'text', size: 'long', maxlength: 255, noempty:true },
			{ name: 'diwakili_oleh', type: 'text', size: 'long', maxlength: 60, noempty:true },
			{ name: 'no_telp', type: 'text', size: 'long', maxlength: 60, noempty:true },
			{ name: 'nama_kegiatan', type: 'text', size: 'long', maxlength: 255, noempty:true },
			{ name: 'tanggal_mulai_kegiatan', type: 'date', size: 'medium', noempty:true },
			{ name: 'tanggal_selesai_kegiatan', type: 'date', size: 'medium', noempty:true },
			{ name: 'pukul', type: 'text', size: 'short', maxlength: 30, noempty:true },
			{ name: 'tempat_kegiatan', type: 'text', size: 'long', maxlength: 255, noempty:true },
			{ name: 'catatan_kegiatan', type: 'text', size: 'long', maxlength: 255},
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:700,
			height:600,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
					loadPage(gs_path + '/' + controller + '/index/');
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		
		
		// Set Action Button
		var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$.ajax({
								url:gs_path+'/'+controller+'/id_auto',
								type:'POST',
								dataType:'JSON',
								}).done(function(data){
									$('#id_surat').setval(data['id_surat_auto']);
									$('#no_surat').setval(data['no_surat_auto']);
							});
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Penyelenggaraan');
							$('#no_surat').readonly(false);
							$('#no_surat, #nama_penyelenggara, #alamat, #diwakili_oleh, #no_telp, #nama_kegiatan, #tanggal_mulai_kegiatan, #tanggal_selesai_kegiatan, #pukul, #tempat_kegiatan, #catatan_kegiatan').val('');
							$('#no_surat').focus();

						} 

						},
						{ label: 'Edit', icon: 'edit', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Penyelenggaraan');
								$('#no_surat').readonly();
								jsonToForm(oSel); $('#no_surat').focus();
								$('#id_surat').setval(oSel['id_surat']);
							} 
						} },
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['id_surat']);
							} 
						}}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
	<form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
    	<td>
    		<input id="id_surat" name="id_surat" type="hidden" />
    	</td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Surat</td>
        <td><input id="no_surat" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Penyelenggara</td>
        <td><input id="nama_penyelenggara" /></td>
    </tr>    
    <tr>
        <td class="label" style="width:150px">Alamat</td>
        <td><textarea id="alamat" name="alamat" /></td>
    </tr>    
	<tr>
        <td class="label" style="width:150px">Diwakili Oleh</td>
        <td><input id="diwakili_oleh" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">No Telp</td>
        <td><input id="no_telp" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Kegiatan</td>
        <td><textarea id="nama_kegiatan" name="nama_kegiatan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal Mulai kegiatan</td>
        <td><input id="tanggal_mulai_kegiatan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal Selesai kegiatan</td>
        <td><input id="tanggal_selesai_kegiatan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Pukul</td>
        <td><input id="pukul" />00-00 S/D 24-00</td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tempat Kegiatan</td>
        <td><textarea id="tempat_kegiatan" name="tempat_kegiatan" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Catatan Kegiatan</td>
        <td><textarea id="catatan_kegiatan" name="catatan_kegiatan" /></td>
    </tr>
    </table>
	</form>
</div>